#ifndef NATRIUM_UTIL_CONCURRENT_H
#define NATRIUM_UTIL_CONCURRENT_H

#include "stdafx.h"

namespace natrium {
	namespace util {
		template <typename T>
		class ConcurrentQueue {
		public:
			void push(const T& item) {
				std::unique_lock<std::mutex> lock(mMutex);
				mQueue.push_back(item);
				mCondition.notify_one();
			}

			void push(T&& item) {
				std::unique_lock<std::mutex> lock(mMutex);
				mQueue.push_back(std::move(item));
				mCondition.notify_one();
			}

			T pop() {
				std::unique_lock<std::mutex> lock(mMutex);
				while (mQueue.empty())
					mCondition.wait(lock);

				T result(mQueue.front());
				mQueue.pop_front();

				return result;
			}
		private:
			std::deque<T> mQueue;
			std::mutex mMutex;
			std::condition_variable mCondition;
		};
	}
}

#endif
